<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>index</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        body {
            min-width: 320px;
        }

        nav {
            border: 1px solid red;
            height: 60px;
            display: flex;
            align-items: center;
            justify-content: space-between;
            position: relative;
            padding: 0 20px;
            background: #000000;
        }

        nav .logo {
            cursor: pointer;
        }

        nav ul#nav_ul {
            display: block;
        }

        nav ul#nav_ul li {
            list-style: none;
            display: inline-block;
            /* margin-right: 20px; */
            padding: 0 20px;
            cursor: pointer;
            color: white;
        }

        nav ul#nav_ul li:hover {
            color: lightblue;
        }

        nav ul#nav_ul li.actived {
            color: aqua;
        }

        nav #menu_icon {
            display: none;
        }

        @media screen and (max-width: 980px) {
            nav ul#nav_ul {
                display: none;
                width: 100%;
                position: absolute;
                top: 60px;
                left: 0;
            }

            nav ul#nav_ul li {
                display: block;
            }

            nav #menu_icon {
                display: inline-block;
                cursor: pointer;
            }
        }

        @media screen and (min-width: 980px) {
            nav ul#nav_ul {
                display: block;
            }
        }
    </style>
</head>

<body>
    <nav>
        <img class="logo" src="./images/logo.png" alt="">
        <ul id="nav_ul">
            <li class="actived">首页</li>
            <li>关于我们</li>
            <li>服务</li>
            <li>联系我们</li>
        </ul>
        <img id="menu_icon" src="./images/menu.png" alt="">
    </nav>
    <script>
        var menu_icon = document.getElementById("menu_icon");
        var nav_ul = document.getElementById("nav_ul");
        var nav_ul_li = nav_ul.children;
        for (let i = 0; i < nav_ul_li.length; i++) {
            menu_icon.onclick = function () {
                var isShow = nav_ul.style.display;
                if (isShow !== "block") {
                    nav_ul.style.display = "block";
                } else {
                    nav_ul.style.display = "none";
                }
            };
        };
        for (let i = 0; i < nav_ul_li.length; i++) {
            const element = nav_ul_li[i];
            element.onclick = function () {
                for (let j = 0; j < nav_ul_li.length; j++) {
                    const every = nav_ul_li[j];
                    if (every.getAttribute("class") == "actived") {
                        every.removeAttribute("class", "actived");
                    }
                }
                element.setAttribute("class", "actived");
            };
        };
    </script>
</body>

</html>